{% extends 'base.html' %}
{% block content %}
<section class="content">
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
        <div class="box pt-5 pb-5">
                <form id="put" class="form" enctype="multipart/form-data" action="" method="post">
                    {% csrf_token %}
                    {% for j in data %}
                    <div class="form-group row">
                        <label class="col-form-label col-2 text-right">菜单名<span class="text-danger">*</span></label>
                        <div class="col-10">
                            <input type="text" name="name" value="{{ j.name }}" class="form-control" placeholder="菜单名">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-form-label col-2 text-right">Url<span class="text-danger">*</span></label>
                        <div class="col-10">
                            <input type="text" name="url" value="{{ j.url }}" class="form-control" placeholder="url" readonly>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-form-label col-2 text-right">Icon<span class="text-danger">*</span></label>
                        <div class="col-10">
                            <input type="text" name="icon" value="{{ j.icon }}" class="form-control" placeholder="Icon">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-form-label col-2 text-right">排序号<span class="text-danger">*</span></label>
                        <div class="col-10">
                            <input type="number" name="order_num" value="{{ j.order_num }}" class="form-control" placeholder="1000">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-form-label col-2"></label>
                        <div class="col-10">
                            <input type="submit" value="保存" class="form-control bg-danger">
                        </div>
                    </div>
                    {% endfor %}
                </form>
        </div>
        </div>
    </div>
</div>
</section>
{% block custom_js %}
<script>
// 提交，FORM  ID
$("#put").submit(function () {
    var options = {
        success: showRespone,  //ajaxForm提交成功后，执行函数
        resetForm: false,      //执行完毕后是否重设表单
        datetype: 'json',      //数据类型
    }
    $("#put").ajaxSubmit(options);
    return false;
})

function showRespone(data) {
    if(data.status === 1){
        //操作成功
        layui.use('layer',function () {
            var layer=layui.layer;
            info = data.info
            layer.alert(info,{
                icon: 6,
                btn: '确定',
                skin: 'layer-ext-moon',
                yes: function () {
                    window.location.reload()
                },

            })
        })
    }else {
        //操作失败
        layui.use('layer',function () {
            var layer=layui.layer;
            info = data.info
            layer.alert(info,{
                icon: 5,
                skin: 'layer-ext-moon',
            })
        })
    }
}
</script>
    <script>
   //修改
   function edit_type(mid,action) {
        layui.use('layer', function () {
            var layer=layui.layer;
            layer.open({
                type: 2,   //1是静态内容层，2是iframe层，可用连接
                area: ['600px', '350px'],
                title: '编辑',
                maxmin: true,
                slideToggle: false,
                content:"/login/menu/" + mid + "/" + action,
                end: function () {
                    location.reload() //弹窗完成后，重载父页面
                }
            })
        })
   }
</script>
{% endblock %}
{% endblock %}